using JT808Protocol.Common;
using System;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location.LocationAddition
{
    /// <summary>
    /// 进出区域/路线报警附加信息消息体
    /// </summary>
    public class LaInOutArea_0x12 : ILocationAddition
    {
        /// <summary>
        /// 位置类型
        /// </summary>
        [JsonPropertyName("位置类型")] public byte LocationType { get; set; }

        /// <summary>
        /// 区域或路线ID
        /// </summary>
        [JsonPropertyName("区域或路线ID")] public uint AreaOrLineID { get; set; }

        /// <summary>
        /// 方向，0：进；1：出
        /// </summary>
        [JsonPropertyName("方向 0：进；1：出")] public byte Direction { get; set; }

        public override ILocationAddition ReadEntity(ReadOnlySpan<byte> source, int startIndex)
        {
            DataLength = (byte)(source[startIndex + 1] + 2);
            if (DataLength != 2 + 6)
            {
                //Logger.Warn($"位置附加信息的进出区域/路线报警信息长度错误，略过解析");
                return null;
            }

            LocationType = source[startIndex + 2];

            AreaOrLineID = ParseHelper.Uint32(ref source, startIndex + 3);

            Direction = source[startIndex + 7];

            return this;
        }
    }
}